package com.bee.test;

import java.util.List;

import org.junit.jupiter.api.Test;

import com.bee.pojo.Level;
import com.bee.pojo.User;
import com.bee.service.UserService;
import com.bee.service.UserServiceImpl;

public class JDBCTester {
	private UserService us = new UserServiceImpl();

	@Test
	public void testInsert() {
		char[] name = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
				'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
		User user = new User();

		for (int i = 0; i < 20; i++) {

			StringBuilder sb = new StringBuilder();
			for (int j = 0; j < 5; j++) {
				sb.append(name[(int) (Math.random() * 25)]);
			}
			user.setNickname(sb.toString());

			user.setRegtime("2018-" + (int) (Math.random() * 11 + 1));
			user.setPoints((int) (Math.random() * 200));
			user.setGender(Math.random() < 0.4 ? "女" : "男");
			user.setCid((int) (Math.random() * 4 + 1));

			us.addUser(user);
		}
	}

	@Test
	public void testDelete() {
		us.delUserById(20);
	}

	@Test
	public void testModify() {
		us.modifyUserPointsById(5, 159);
	}

	@Test
	public void testSelectDyn4And() {
		User user = new User();
//		user.setId(3);
//		user.setNickname("fe");
//		user.setGender("女");
//		user.setPoints(23);
		user.setRegtime("-4");
		List<User> list = us.getUsers4And(user);
		for (User u : list) {
			System.out.println(u);
		}
	}

	@Test
	public void testSelectDyn4Or() {
		User user = new User();
//		user.setId(50);
//		user.setNickname("m");
		user.setRegtime("-4");
//		user.setPoints(23);
		user.setGender("女");
		List<User> list = us.getUsers4Or(user);
		for (User u : list) {
			System.out.println(u);
		}
	}

	@Test
	public void testSelectPoints() {
		List<User> list = us.getPointsGtVal(150);
		for (User u : list) {
			System.out.println(u);
		}
	}

	@Test
	public void testSelectMulti() {
		List<Level> list = us.getUsersMulti();
		for (Level user : list) {
			System.out.println(user);
		}
	}
}
